#! /bin/bash


. /opt/module/rebate-report/configration/config.sh

result_url=${BI_URL}
result_database=${BI_DATABASE}
result_username=${BI_USERNAME}
result_password=${BI_PASSWORD}

if [ -n "$2" ] ;then
        echo "如果是输入的日期按照取输入日期"
        do_date=$2
else
        echo "====没有输入数据的日期，取当前时间的前一天===="
        do_date=`date -d yesterday +"%Y-%m-%d"`
fi
echo "日期为：$do_date"

#每天无分区全量
export_tb(){
sqoop export -D mapred.job.queue.name=root.tianyan \
--connect "jdbc:mysql://$result_url/$result_database?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&tinyInt1isBit=false" \
--username  $result_username \
--password  $result_password \
--table $1 \
-m $2 \
--export-dir hdfs://nameservice:8020/warehouse/dw/$3 \
--fields-terminated-by '\001' \
--input-null-string '\\N' \
--input-null-non-string '\\N'
}

#清空表
app_cart_detail="delete from app_cart_detail where dt in (select dt from app_rebate_partition where business_type = 2);"
app_station_detail="delete from app_station_detail where dt in (select dt from app_rebate_partition where business_type = 2);"


export_tmp_station_detail(){
mysql -h${result_url}  -P3306  -u${result_username} -p${result_password} ${result_database} -e  "${del_rebate_company_station}"
export_tb "app_station_detail" "1" "tmp/tmp_station_detail"
}

export_tmp_cart_detail(){
mysql -h${result_url}  -P3306  -u${result_username} -p${result_password} ${result_database} -e  "${del_rebate_company}"
export_tb "app_cart_detail" "1" "tmp/tmp_cart_detail"
}

case $1 in
"app_station_detail")
export_tmp_station_detail
;;
"app_cart_detail")
export_tmp_cart_detail
;;
"all")
export_tmp_station_detail
export_tmp_cart_detail
;;
esac